﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Zwms.Data.BusinessObjects;
using Zwms.Data.CommonObject;

namespace Zwms.Client.InfoSys
{
    public partial class SysOptLogQueryWnd : UserControl
    {
        #region 成员变量
        private SysOptLog _currentQueryRecord;
        private PagerIndex _pagerIndex;
        private CommonUI.WaitForm _waitForm = new CommonUI.WaitForm();
        #endregion

        #region 构造函数
        public SysOptLogQueryWnd()
        {
            InitializeComponent();
            InitBtnImage();
            InitControl();
        }
        #endregion

        #region 私有函数
        private void InitBtnImage()
        {
            this.btnQuery.Image = global::Zwms.Client.Properties.Resources.query;
        }

        private void InitControl()
        {
            ResetDataPager();
            ResetQueryRecord();
            RefreshData();
        }

        private void ResetDataPager()
        {
            dataPager.PageCurrent = 1;
            dataPager.PageSize = CommonDefine.iPageSize;
        }

        private void ResetQueryRecord()
        {
            _currentQueryRecord = new SysOptLog();
        }

        private SysOptLog GetRecordFromUI()
        {
            SysOptLog record = new SysOptLog();
            record.LogNo = this.tbLogNo.Text.Trim();
            if (this.dpuLogDate.SelectDateTime == null)
            {
                record.OptDate = String.Empty;
            }
            else 
            {
                record.OptDate = this.dpuLogDate.SelectDateTime;
            }
            
            record.UserCode = this.tbUserCode.Text.Trim();
            return record;
 
        }

        private void RefreshData()
        {
            //读入部分数据
            _pagerIndex = new PagerIndex(dataPager.PageCurrent, CommonDefine.iPageSize);
            MyDataBind(_currentQueryRecord, _pagerIndex);
        }

        private void MyDataBind(SysOptLog queryRecord, PagerIndex pIndex)
        {
            try
            {
                ServiceReferenceZwms.ServiceZwmsClient client = new ServiceReferenceZwms.ServiceZwmsClient();
                IList<SysOptLog> queryList = client.QueryOptLogList(queryRecord, ref pIndex);
                LoadBillDetail(queryList);
            }
            catch
            {
            }
        }

        private void LoadBillDetail(IList<SysOptLog> recordList)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                this.sysOptLogBindingSource.DataSource = null;
                this.sysOptLogBindingSource.DataSource = recordList;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            ResetDataPager();
            this._currentQueryRecord = GetRecordFromUI();
            this.RefreshData();
            
        }

        private void dataPager_BtnClick(object sender, EventArgs e)
        {
            _pagerIndex.CurrentPageIndex = dataPager.PageCurrent;
            MyDataBind(_currentQueryRecord, _pagerIndex);
        }
        #endregion
    }
}
